document.addEventListener("DOMContentLoaded", () => {
    const messageText = document.getElementById("message-text");
    const chatContainer = document.getElementById("chat-container");

    messageText.addEventListener("input", function() {
        // reset height to recalc scrollHeight correctly
        this.style.height = "auto";
        const maxHeight = chatContainer.offsetHeight / 5;
        this.style.height = Math.min(this.scrollHeight, maxHeight) + "px";
    });
});